<div class="clr"></div>
<div class="uploadcsv">
    <h3><?php echo $this->lang->line('upload_title'); ?></h3>
    <h4><?php echo $this->lang->line('upload_titleindex'); ?></h4>
    <?php echo "<label for='disabledSelect' style='color:red;'>".$this->session->flashdata('message')."</label>"; ?>
    <form action="" method="post" enctype="multipart/form-data" >
        <table width="375" border="0" id="upfile">
            <tr>
                <td>
                    <input type="text" name="txtfile" id="txtfile" onclick="uploadfile();" value="<?php if(isset($txtfile))echo $txtfile; ?>" />
                    <input type="button" value="<?php echo $this->lang->line('Home_Browser');?>" onclick="uploadfile()" />
                    <br/>
                    <span class="error"><?php echo form_error('txtfile'); ?></span>
                    <input type="file" name="fileupload" size="20" id="btnupload" accept="text/plain,csv/plain" />
                </td>
            </tr>
            <tr>
                <td><input type="submit" name="btnupload" value="<?php echo $this->lang->line('upload_title');?>" /></td>
            </tr>
        </table>
    </form>
</div>
<!-- /#page-wrapper -->
<!-- BEGIN dialog message -->
<div id="dialog" title="<?php echo $this->lang->line('CR_dialog_title'); ?>">
    <?php echo isset($message) ? $message : ''; ?>
</div>
<!-- END dialog message -->
<!-- function check check file extension -->
<script>
    function uploadfile() {
        $('#btnupload').click();
        $('#btnupload').change(function(){
            var fileVal = document.getElementById("btnupload");
            var str = fileVal.value;
            var arr =  str.replace("fakepath", "..");
            $('#txtfile').val(arr);
        })
    }
    $(document).ready(function() {
<?php if (isset($flag) && $flag == TRUE): ?>
            $(function() {
                $("#dialog").dialog({
                    modal: true,
                    close: function() {
                        window.location.href = '<?php echo base_url('/time-card-manipulation'); ?>';
                    },
                    buttons: [{
                        text: "<?php echo $this->lang->line('MC019');?>",
                        click: function() {
                            window.location.href = '<?php echo base_url('/time-card-manipulation'); ?>';
                        },
                    }]
                });
            });
<?php elseif (isset($flag) && $flag == FALSE): ?>
            $(function() {
                $("#dialog").dialog({
                    modal: true,
                    close: function() {
                        $( this ).dialog( "close" );
                    },
                    buttons: [{
                        text: "<?php echo $this->lang->line('MC019');?>",
                        click: function() {
                            $( this ).dialog( "close" );
                        },
                    }]
                });
            });
<?php endif; ?>
    });  
</script>
